<?php
namespace App\Http\Controllers\H5;

use App\Service\H5\WorkhourService;
use Illuminate\Http\Request;

class WorkhourController extends BaseController
{
    //列表
    public function index(Request $request)
    {
        $pas['depart_id'] = $request->post('depart_id', 0);
        $res = WorkhourService::index($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    // 详情
    public function getOne(Request $request)
    {
        $id = $request->post('id', 0);
        $res = WorkhourService::getOne($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

   //修改
   public function modify(Request $request)
   {
       $id = $request->post('id', 0);
       $pas['title'] = $request->post('title', '');
       if ($id) {
           $res = WorkhourService::modify($id, $pas);
       } else {
           $res = WorkhourService::add($pas);
       }
       if ($res['code'] < 0) {
           return self::toJson(-2, $res['msg']);
       }
       return self::toJson();
   }

   //删除
   public function del(Request $request)
   {
       $id = $request->post('id', 0);
       $res = WorkhourService::del($id);
       if ($res['code'] < 0) {
           return self::toJson(-2, $res['msg']);
       }
       return self::toJson();
   }

   //内容新增
   public function cntAdd(Request $request)
   {
       $pas['wh_id'] = $request->post('wh_id', 0);
       $pas['cnt'] = $request->post('cnt', '');
        $res = WorkhourService::cntAdd($pas);
       if ($res['code'] < 0) {
           return self::toJson(-2, $res['msg']);
       }
       return self::toJson();
   }

   //内容修改
   public function cntModify(Request $request)
   {
       $id = $request->post('id', 0);
       $pas['cnt'] = $request->post('cnt', '');
        $res = WorkhourService::cntModify($id, $pas);
       if ($res['code'] < 0) {
           return self::toJson(-2, $res['msg']);
       }
       return self::toJson();
   }

   //内容删除
   public function cntDel(Request $request)
   {
       $id = $request->post('id', 0);
        $res = WorkhourService::cntDel($id);
       if ($res['code'] < 0) {
           return self::toJson(-2, $res['msg']);
       }
       return self::toJson();
   }
}